// Sage Android Client.
// Connect to a Sage server, remotely execute commands and display results.
//
// Copyright (C) 2010, Harald Schilly <harald.schilly@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package org.sagemath.android.interacts;

import org.sagemath.android.Calculation;
import org.sagemath.android.R;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

/**
 * Calculate the solution to a system of linear equations, e.g. a 3 x 4 Matrix
 * of numerical value fields that are for a 3x3 matrix A and a 3x1 vector b and
 * then display the solution vector below.
 * 
 * @author Harald Schilly
 */
public class System extends AbstractInteract {
  public System() {
    super(R.layout.system);
  }
  
  private Button solve;
  
  private TextView output;
  
  /*
   * (non-Javadoc)
   * @see org.sagemath.android.interacts.AbstractInteract#build()
   */
  @Override
  protected void init() {
    solve = (Button) myView.findViewById(R.id.systemBtnSolve);
    output = (TextView) myView.findViewById(R.id.systemOutput);
    
    solve.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        output.setText("calculating ...");
        calculate(Integer.toString((int) (42 * Math.random())));
      }
    });
  }
  
  /*
   * (non-Javadoc)
   * @see
   * org.sagemath.android.interacts.AbstractInteract#onError(java.lang.String)
   */
  @Override
  protected void onError(String error) {
    output.setText("Error: " + error);
  }
  
  /*
   * (non-Javadoc)
   * @see
   * 
   * org.sagemath.android.interacts.AbstractInteract#onResult(org.sagemath.android
   * .Calculation)
   */
  @Override
  protected void onResult(Calculation c) {
    output.setText(c.getResult());
  }
  
  /*
   * (non-Javadoc)
   * @see org.sagemath.android.interacts.AbstractInteract#reset()
   */
  @Override
  public void reset() {
    // TODO Auto-generated method stub
    
  }
  
}
